import { listSoftwareCategoryTree } from '@/apis/asset/common';
import type { TreeNodeData } from '@arco-design/web-vue';
import { ref } from 'vue';

/** 软件类型模块 */
export function softwareCategory(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const softwareCategoryList = ref<TreeNodeData[]>([])

  const getSoftwareCategoryList = async (name?: string) => {
    try {
      loading.value = true
      const res = await listSoftwareCategoryTree({ description: name })
      softwareCategoryList.value = res.data
      options?.onSuccess && options.onSuccess()
    } finally {
      loading.value = false
    }
  }
  return { softwareCategoryList, getSoftwareCategoryList, loading }
}
